package com.gitee.dolt.boot.controller;

import com.gitee.dolt.annotation.security.PreAuth;
import com.gitee.dolt.annotation.log.SysLog;
import com.gitee.dolt.core.base.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.Serializable;
import java.util.List;

/**
 * 删除
 *
 * @author LYH
 */
public interface DeleteController<Entity, Id extends Serializable> extends BaseController<Entity> {

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    @SysLog("'删除:' + #ids")
    @PreAuth("hasAnyPermission('{}delete')")
    default Result delete(@RequestBody List<Id> ids) {
        Result result = handlerDelete(ids);
        if (result.isExecDefault()) {
            getBaseService().removeByIds(ids);
        }
        return result;
    }

    /**
     * 自定义删除
     *
     * @param ids id
     * @return 返回execDefault=true, 调用默认更新, 返回其他不调用默认更新
     */
    default Result handlerDelete(List<Id> ids) {
        return Result.execDefault(true);
    }

}
